package edu.calvin.djs32.cs214.interpreters.frontend;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;
import org.norecess.antlr.ANTLRTester;

import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.cs214.hobbes2008.StringTIR;
import edu.calvin.cs214.hobbes2008.TupleTIR;


public class Hobbes2008TIRBuilderTest {
	private ANTLRTester myTester;

	@Before
	public void setUp() {
		myTester = new ANTLRTester(new Hobbes2008FrontEnd());
	}
	
	@Test
	public void shouldBuildIntegerTIR() {
	  assertEquals(new IntegerTIR(5), myTester.scanInput("5").parseAs("expression").treeParseAs("expression"));
	  assertEquals(new IntegerTIR(19), myTester.scanInput("19").parseAs("expression").treeParseAs("expression"));
	  assertEquals(new IntegerTIR(0x123f), myTester.scanInput("0x123f").parseAs("expression").treeParseAs("expression"));
	}
	
	@Test
	public void shouldBuildStringTIR(){
		assertEquals(new StringTIR("foo"), myTester.scanInput("'foo'").parseAs("expression").treeParseAs("expression"));
		assertEquals(new StringTIR("bar"), myTester.scanInput("'bar'").parseAs("expression").treeParseAs("expression"));
		assertEquals(new StringTIR("foo bar"), myTester.scanInput("'foo bar'").parseAs("expression").treeParseAs("expression"));
	}
	
	@Test
	public void shouldBuildTupleTIR() {
	  assertEquals(new TupleTIR(), myTester.scanInput("()").parseAs("expression").treeParseAs("expression"));
	  assertEquals(new TupleTIR(new IntegerTIR(5)), myTester.scanInput("(5)").parseAs("expression").treeParseAs("expression"));
	  assertEquals(new TupleTIR(new IntegerTIR(5), new IntegerTIR(6), new IntegerTIR(7)), myTester.scanInput("(5, 6, 7)").parseAs("expression").treeParseAs("expression"));
	  assertEquals(new TupleTIR(new IntegerTIR(5), new TupleTIR(new IntegerTIR(6), new IntegerTIR(7))), myTester.scanInput("(5, (6, 7))").parseAs("expression").treeParseAs("expression"));
	  assertEquals(new TupleTIR(new IntegerTIR(5), new StringTIR("foo"), new IntegerTIR(7)), myTester.scanInput("(5, 'foo', 7)").parseAs("expression").treeParseAs("expression"));
	}

}
